﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BlackBBS.Infrastructure.Repository;
using BlackBBS.Models.Data;
using System.IO;
using System.Diagnostics;
using System.Configuration;

namespace BlackBBSWebServer
{
    public class WebRepository
    {
        private static WebRepository _instance;

        public IServerRepository Repository { get; set; }
        public ConfigSettings ConfigSettings { get; set; }

        private WebRepository()
        {
        }

        public void Init()
        {
            this.ConfigSettings = ConfigSettings.Setup();

            var dbStore = ConfigurationManager.AppSettings["dbstore"];
            switch (dbStore.ToString().ToLower())
            {
                case "redis":
                    this.Repository = new BlackBBS.Infrastructure.Repository.SiderServerRepository();
                    break;

                default:
                    this.Repository = new BlackBBS.Infrastructure.Repository.XMLServerRepository();
                    break;
            }               
            this.Repository.Init(this.ConfigSettings);
        }

        public static WebRepository Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new WebRepository();
                    _instance.Init();
                }
                return _instance;
            }
        }
    }
}
